<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Blog extends CI_Controller {
	function __construct() {
		parent::__construct();
		$this->load->model('core_model');
	}
	
	function category($code='') {
		$data['pages'] 	  	   = 'kategori';
		$category 	   		   = $this->core_model->getwheredata('tb_category', array('category_code'=>$code));
		$data['category_name'] = $category[0]['category_name'];
		$data['category_code'] = $category[0]['category_code'];
		
		$data['row']	 = $this->core_model->countalldata('view_posting', array('category_code'=>$data['category_code']));
		$data['article'] = $this->core_model->getwheredata('view_posting', array('category_code'=>$data['category_code']), 'stateid desc', array(0, 7));
		
		$this->load->view('template', $data);
	}
	
	function read($stateid='', $permalink='') {
		//set page
		$data['pages']    = 'read';
		//get data model
		$data['readnews'] = $this->core_model->getwheredata('view_posting', array('permalink'=>$permalink, 
																					'stateid'=>$stateid, 
																					'publish_status'=>'Y'));
		$data['random']	  = $this->core_model->getranddata('view_posting', 
																array("permalink"=>" <> '".$permalink."'", "stateid"=>" <> '".$stateid."'"),
																array(0, 5)
															);
		//update page view count
		$data['views'] 	  = intval($data['readnews'][0]['viewcount']) + 1;
		$this->core_model->updatedata('tb_posting', 
										array('viewcount'=>$data['views']), 
										array('stateid'=>$data['readnews'][0]['stateid'])
									);
		//load view
		$this->load->view('template', $data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */